package hongcaosp.app.android.user.settings.safety.bind.presenter;

import android.text.TextUtils;

import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.impl.PasswordModleImpl;
import hongcaosp.app.android.user.settings.safety.bind.iview.BindNewPhoneIView;
import hongcaosp.app.android.user.settings.safety.bind.iview.CheckNowPhoneIView;
import xlj.lib.android.base.component.BasePresenter;
import xlj.lib.android.base.toastcompat.ToastManager;

public class BindNewPhonePresenter extends BasePresenter {
    private BindNewPhoneIView iView;
    private PasswordModleImpl passwordModle;

    public BindNewPhonePresenter(BindNewPhoneIView iView) {
        this.iView = iView;
        passwordModle = new PasswordModleImpl();
    }

    public void sendCode(String mobile) {
        if (TextUtils.isEmpty(mobile)) {
            ToastManager.getInstance().showToast("请输入手机号");
            return;
        }
        passwordModle.sendCode(mobile, 4, new DataCallBack() {
            @Override
            public void onGetData(Object data) {
                super.onGetData(data);
                iView.sendCodeOver();
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                ToastManager.getInstance().showToast(errorMessage);
            }
        });
    }

    public void check(String mobile, String code) {
        if (TextUtils.isEmpty(mobile)) {
            ToastManager.getInstance().showToast("请输入手机号");
            return;
        }
        if (TextUtils.isEmpty(code)) {
            ToastManager.getInstance().showToast("请输入验证码");
            return;
        }
        passwordModle.bindingMobile(UserToken.getDefault().getToken(), 2, mobile, code, new DataCallBack<BaseResponse>() {
            @Override
            public void onGetData(BaseResponse data) {
                super.onGetData(data);
                iView.bindOver();
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                ToastManager.getInstance().showToast(errorMessage);
            }
        });
    }
}
